package listbyorder.access101_200.test121;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/8 13:09
 */
public class Solution2 {

    // 转化成求解最长子序和
    public int maxProfit(int[] prices) {
        int ans = 0;
        int[] temp = new int[prices.length];
        for (int i = 0; i < prices.length - 1; i++) {
            temp[i] = prices[i + 1] - prices[i];
        }
        int cur = 0;
        for (int i = 0; i < temp.length; i++) {
            cur = Math.max(cur + temp[i], temp[i]);
            ans = Math.max(ans, cur);
        }
        return ans;
    }
}
